import { Injectable } from '@angular/core';
import { Subject }    from 'rxjs/Subject';

@Injectable()
export class HistoryTimeChangeService {

  //  Observable time number sources
  private timeArrSource = new Subject<number[]>();

  //  Observable time number streams
  timeArr$=this.timeArrSource.asObservable()

  changeTimeArr(times:string[]){
    let numberedTime:number[]=[]
    if(times.length>0){
      times.forEach(t=>{
        numberedTime.push(this.timeString2number(t))
      })
    }
    this.timeArrSource.next(numberedTime)
  }

  private timeString2number(t:string):number{
    let ti=t.split('-')
    if(ti.length===3){
      return Date.UTC(+ti[0],+ti[1]-1,+ti[2])//UTC时间 早上8:0:0
    }
    else{
      return Date.now()
    }
  }

  constructor() { }

}
